package com.mallcai.bigdata.ladon.client.export;

import lombok.Builder;
import lombok.Data;

import java.io.Serializable;

/**
 * described :导出策略,必须指定文件名称和异步导出信息
 *
 * @author CaKeDou
 * @date 2019-09-26 16:09
 * Modify:
 */
@Data
@Builder(builderMethodName = "hiddenBuilder")
public class ExportStrategy implements Serializable {
    /**
     * 文件类型 xls xlsx csv
     */
    private ExportFileTypeEnum fileType;

    /**
     * 异步导出信息
     */
    private AsyncInfo asyncInfo;

    /**
     * true存至OSS,false存至本地
     */
    private boolean saveToOss;

    /**
     * true压缩,false正常
     */
    private boolean compress;

    public enum ExportFileTypeEnum implements Serializable{
        /**
         * 07版以下excel
         */
        XLS,
        /**
         * 07版以上excel
         */
        XLSX,
        /**
         * 逗号分隔符文件
         */
        CSV
    }

    public static class AsyncInfo implements Serializable{
        /**
         * true 同步,false 异步
         */
        private boolean async;
        /**
         * 异步时需要一个一个任务编号来轮询最终结果
         */
        private Long    taskId;

        public AsyncInfo(boolean async) {
            this.async = async;
        }

        public boolean isAsync() {
            return async;
        }

        public Long getTaskId() {
            return taskId;
        }

        public void setTaskId(Long taskId) {
            this.taskId = taskId;
        }
    }

    public static ExportStrategyBuilder builder(ExportFileTypeEnum fileType, AsyncInfo asyncInfo) {
        return hiddenBuilder().fileType(fileType).asyncInfo(asyncInfo);
    }

}
